package com.yjhb.android.sbz.fragment;

import android.graphics.Color;
import android.view.View;

import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.adapter.NewUserTaskListAdapter;
import com.yjhb.android.sbz.entity.Task;
import com.yjhb.android.sbz.entity.TaskInfo;
import com.yjhb.android.sbz.manager.ResManager;
import com.yjhb.android.sbz.mvp.new_user_task_list.NewUserTaskListPresenter;
import com.yjhb.android.sbz.mvp.new_user_task_list.NewUserTaskListView;
import com.yjhb.android.sbz.tool.Tool;

import java.util.List;

/**
 * 创建者 zx
 * 创建时间 2020/12/21 10:08
 */
public class NewUserTaskListFragment extends BaseListFragment<NewUserTaskListPresenter, NewUserTaskListAdapter, TaskInfo> implements NewUserTaskListView {
    private final String TAG = "NewUserTaskListFragment";

    @Override
    protected NewUserTaskListAdapter getAdapter() {
        return new NewUserTaskListAdapter(getContext());
    }

    @Override
    protected void initUI() {
        super.initUI();
        tips_tv.setTextColor(Color.RED);
        content_layout.setBackgroundResource(R.color.white);
        content_layout.setPadding(ResManager.dp()*8,0,ResManager.dp()*8,0);
    }

    @Override
    protected CharSequence getTips() {
        return "*该榜单筛选出了适合新用户的悬赏任务";
    }

    @Override
    protected void onLoadData(int size, int current) {
        presenter.getList(size, current);
    }

    @Override
    protected NewUserTaskListPresenter initPresenter() {
        return new NewUserTaskListPresenter(this);
    }

    @Override
    public void onItemClick(int index, Object o) {
        Task task = (Task) o;
        Tool.startEditTaskDetailActivity(getActivity(),task.getId());
    }

    @Override
    public void onViewClick(View view, String msg, int index, Object o) {

    }

//    @Override
//    public void onFailure(int code, String msg) {
//        if (code != -1) {
//            ZxToast.showINFOBottomToast(msg);
//        }
//        smartRefreshLayout.finishLoadmore();
//        smartRefreshLayout.finishRefresh();
//        loadingDialog.cancel();
//    }

    @Override
    public void onLoad(List<TaskInfo> tasks) {
        smartRefreshLayout.finishLoadmore();
        this.dataSet.addAll(tasks);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onRefresh(List<TaskInfo> tasks) {
        loadingDialog.cancel();
        smartRefreshLayout.finishRefresh();
        this.dataSet.clear();
        this.dataSet.addAll(tasks);
        adapter.notifyDataSetChanged();
    }
}
